package la.iok.hzsvn.lewin.movie.services.config;

import la.iok.hzsvn.lewin.cloud.invoker.config.RestServiceInvokerAutoConfiguration;
import la.iok.hzsvn.lewin.cloud.invoker.service.RestServiceInvoker;
import la.iok.hzsvn.lewin.movie.services.MovieServiceInvoker;
import la.iok.hzsvn.lewin.movie.services.MovieServiceInvokerImpl;
import la.iok.hzsvn.lewin.movie.services.OrgUnitIntegration;
import la.iok.hzsvn.lewin.movie.services.OrgUnitIntegrationImpl;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@AutoConfigureAfter(RestServiceInvokerAutoConfiguration.class)
public class MovieServiceAutoConfiguration {
    @ConditionalOnMissingBean(MovieServiceInvoker.class)
    @ConditionalOnBean(RestServiceInvoker.class)
    @Bean
    public MovieServiceInvoker movieServiceInvoker(RestServiceInvoker restServiceInvoker){
        return new MovieServiceInvokerImpl(restServiceInvoker);
    }

    @ConditionalOnMissingBean(OrgUnitIntegration.class)
    @ConditionalOnBean(MovieServiceInvoker.class)
    @Bean
    public OrgUnitIntegration orgUnitIntegration(MovieServiceInvoker movieServiceInvoker){
        return new OrgUnitIntegrationImpl(movieServiceInvoker);
    }
}
